package com.empire.module.sporttery.service.football500ouzdetail;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.empire.module.sporttery.controller.admin.football500ouzdetail.vo.*;
import com.empire.module.sporttery.dal.dataobject.football500ouzdetail.Football500OuzDetailDO;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.util.object.BeanUtils;

import com.empire.module.sporttery.dal.mysql.football500ouzdetail.Football500OuzDetailMapper;

import static com.empire.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.empire.module.sporttery.enums.ErrorCodeConstants.*;

/**
 * 亚盘实时 Service 实现类
 *
 * @author 无敌仙人
 */
@Service
@Validated
public class Football500OuzDetailServiceImpl implements Football500OuzDetailService {

    @Resource
    private Football500OuzDetailMapper football500OuzDetailMapper;

    @Override
    public Integer createFootball500OuzDetail(Football500OuzDetailSaveReqVO createReqVO) {
        // 插入
        Football500OuzDetailDO football500OuzDetail = BeanUtils.toBean(createReqVO, Football500OuzDetailDO.class);
        football500OuzDetailMapper.insert(football500OuzDetail);
        // 返回
        return football500OuzDetail.getId();
    }

    @Override
    public void updateFootball500OuzDetail(Football500OuzDetailSaveReqVO updateReqVO) {
        // 校验存在
        validateFootball500OuzDetailExists(updateReqVO.getId());
        // 更新
        Football500OuzDetailDO updateObj = BeanUtils.toBean(updateReqVO, Football500OuzDetailDO.class);
        football500OuzDetailMapper.updateById(updateObj);
    }

    @Override
    public void deleteFootball500OuzDetail(Integer id) {
        // 校验存在
        validateFootball500OuzDetailExists(id);
        // 删除
        football500OuzDetailMapper.deleteById(id);
    }

    private void validateFootball500OuzDetailExists(Integer id) {
        if (football500OuzDetailMapper.selectById(id) == null) {
            throw exception(FOOTBALL500_OUZ_DETAIL_NOT_EXISTS);
        }
    }

    @Override
    public Football500OuzDetailDO getFootball500OuzDetail(Integer id) {
        return football500OuzDetailMapper.selectById(id);
    }

    @Override
    public PageResult<Football500OuzDetailDO> getFootball500OuzDetailPage(Football500OuzDetailPageReqVO pageReqVO) {
        return football500OuzDetailMapper.selectPage(pageReqVO);
    }

}